import http from "@/utils/http";
import {Page, R} from "./common";
import {AxiosResponse} from "axios";
import {ProvinceHistory} from "@/api/province.ts";
import {Base, Quality} from "@/api/baseQuality.ts";

enum Router {
    airReal = "stationQuality/realTime",
    update = "stationQuality/realTime/update",
    history = "stationQuality/history",
    health = "stationQuality/health",
    predict = "stationQuality/predict",
}

export interface Data {
    stationCode: string;
    positionName: string;
    latitude: string;
    longitude: string;
    cityCode: number;
    stationQuality: StationQuality;
}

export interface StationQuality extends Quality{
    stationCode: string;
}

export interface Station {
    stationCode: string;
    positionName: string;
    latitude: string;
    longitude: string;
    cityCode: number;
    status: boolean;
}


export interface SearchForm {
    id: string,
    range: number;
    timeRange: Date[];
}

export function getAirQualityRealTime(): Promise<AxiosResponse<R<Data[]>>> {
    return http<R<Data[]>>({
        url: Router.airReal,
        method: "get"
    })
}

export function getUpdate() {
    return http<R<null>>({
        url: Router.update,
        method: "get"
    })
}

export function getStationHistory(data: ProvinceHistory): Promise<AxiosResponse<R<StationQuality[]>>> {
    return http<R<StationQuality[]>>({
        url: Router.history,
        method: "post",
        data
    })
}

export function getStationHealth(id: number): Promise<AxiosResponse<R<StationQuality[]>>> {
    return http<R<StationQuality[]>>({
        url: `${Router.health}/${id}`,
        method: "get",
    })
}

export function getStationPredict(id: number) {
    return http<R<Base[]>>({
        url: `${Router.predict}/${id}`,
        method: "get"
    })
}

export function searchHistory(data: SearchForm & Page) {
    return http({
        url: "stationQuality/search",
        method: "post",
        data
    })
}

export function getStation() {
    return http<R<Station[]>>({
        url: "stationQuality",
        method: "get"
    })
}

export function exportHistory(data: SearchForm) {
    return http({
        url: "stationQuality/export",
        method: "post",
        data,
        responseType: "blob"
    })
}
